package beautiful.butterfly.drds.schedule.strategy.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by ibm on 2018/1/20.
 */
class ManagerFactoryTimerTask extends java.util.TimerTask {
    private static transient Logger log = LoggerFactory.getLogger(ManagerFactoryTimerTask.class);
    ManageFactory factory;
    int count = 0;

    public ManagerFactoryTimerTask(ManageFactory aFactory) {
        this.factory = aFactory;
    }

    public void run() {
        try {
            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
            if (this.factory.zooKeeperManager.checkZookeeperState() == false) {
                if (count > 5) {
                    log.error("Zookeeper����ʧ�ܣ��ر����е��������������Zookeeper������......");
                    this.factory.reStart();

                } else {
                    count = count + 1;
                }
            } else {
                count = 0;
                this.factory.refresh();
            }

        } catch (Throwable ex) {
            log.error(ex.getMessage(), ex);
        } finally {
            factory.timerTaskHeartBeatTS = System.currentTimeMillis();
        }
    }
}
